package com.atguigu.gmall.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wjh
 * @version 1.0
 * @date 2021/7/16 19:11
 * 秒杀相关的交换机和队列绑定的创建
 */
@Configuration
public class SeckillRabbitConfig {

    /**
     * 创建秒杀的交换机
     * @return
     */
    @Bean("seckillExchange")
    public Exchange seckillExchange(){
        return ExchangeBuilder.topicExchange("seckill_exchange").build();
    }

    /**
     * 创建秒杀的消息队列
     * @return
     */
    @Bean("seckillQueue")
    public Queue seckillQueue(){
        return QueueBuilder.durable("seckill_queue").build();
    }

    /**
     * 创建绑定
     * @param seckillExchange
     * @param seckillQueue
     * @return
     */
    @Bean
    public Binding seckillBing(@Qualifier("seckillExchange") Exchange seckillExchange,
                              @Qualifier("seckillQueue") Queue seckillQueue){
        return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckill.order.*").noargs();
    }

}
